var channelId = getQuery("channelId");

window.onload = function () {
    findById()
}

function findById() {
    axios.get("/stick/findById",{params:{stickId:channelId}}).then(resp =>{
        var info = resp.data;
        $("head").src = "/productImg/"+ info.user.img
        $("lname").innerHTML = info.user.name
        $("ldate").innerHTML = info.user.register
        $("ldata").innerHTML =`<tr><td>${info.stickTitle}</td><td>${info.stickContent}</td><td>${info.postDate}</td></tr>`

        var str = ""
        info.replyList.forEach(n =>{
            str +=`<tr><td>
                        <img src="/productImg/${n.user.img}" width="30" height="30"><br>
                        <span>${n.user.name}</span><br>
                        <span>${n.user.register}</span>
                    </td>
                    <td>${n.title}</td>
                    <td>${n.content}</td></tr>`
        })
        $("newdata").innerHTML = str
    })
}

function insertReply() {
    axios.get("/reply/add",{
        params: {
            stickId: channelId,
            title:$("newTitle").value,
            content:$("newContent").value
        }
    }).then(r =>{
        var data = r.data;
        if (data == "ok"){
            findById()
        }else if (data == "nologin"){
            location.href = "/login.html"
        }
    })
}